package com.wanmait.recruit.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruit.pojo.CompanyAuthc;
import com.wanmait.recruit.pojo.Person;
import com.wanmait.recruit.pojo.PersonSystemInfo;
import com.wanmait.recruit.service.CompanyAuthcService;
import com.wanmait.recruit.service.PersonSystemInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@Transactional
@RequestMapping("/manage/companyAuthc")
public class CompanyAuthcController {
    @Resource
    private CompanyAuthcService companyAuthcService;
    @Resource
    PersonSystemInfoService personSystemInfoService;
    @RequestMapping("companyAuthcList")
    public void companyAuthcList(){

    }
    @RequestMapping("companyAuthcListData")
    public ModelAndView companyAuthcListData(String name, Integer pageNum){
        ModelAndView modelAndView = new ModelAndView();
        PageInfo<CompanyAuthc> pageInfo = companyAuthcService.findAll(name, pageNum);
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("/manage/companyAuthc/companyAuthcListData");
        return modelAndView;
    }
    @RequestMapping("companyAuthcisPass")
    public String companyAuthcisPass(Integer id){
        companyAuthcService.isPass(id);
        Person person = companyAuthcService.findPersonById(id);
        PersonSystemInfo personSystemInfo = new PersonSystemInfo();
        personSystemInfo.setPersonId(person.getId());
        personSystemInfo.setContent("恭喜你，你的公司审核已通过");
        personSystemInfoService.insert(personSystemInfo);
        return "redirect:/manage/companyAuthc/companyAuthcList";
    }
    @RequestMapping("companyAuthcnotPass")
    public String companyAuthcnotPass(Integer id,String reason){
        companyAuthcService.notPass(id, reason);
        Person person = companyAuthcService.findPersonById(id);
        PersonSystemInfo personSystemInfo = new PersonSystemInfo();
        personSystemInfo.setPersonId(person.getId());
        personSystemInfo.setContent("对不起，你的公司审核未能通过，原因："+reason);
        personSystemInfoService.insert(personSystemInfo);
        return "redirect:/manage/companyAuthc/companyAuthcListData";
    }
    @RequestMapping("delete")
    public String delete(Integer id){
        companyAuthcService.deleteById(id);
        return "redirect:/manage/companyAuthc/companyAuthcList";
    }
}
